<?php
/*
cmfit
Copyright (C) 2000-2007 Andreas Bengtsson

Email: anteman@users.sourceforge.net

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

// -------------------------------------------------------------

function ascdump($str){
$res="";
 for ($i = 0; $i <= (strlen($str)-1); $i++) {
    $res.=$str[$i].ord($str[$i]).",";
 }
 return $res;
}


// -------------------------------------------------------------
function stripdir($str){
 if( substr ($str, -1) == "/" || substr ($str, -1) == "\\"){
 	return substr($str,0,strlen($str)-1);
 }
}

// -------------------------------------------------------------

function addseparator($str){
	if(substr($str,strlen($str)-strlen("/"))!="/"){
	 	$str.="/";
 	}
 	return $str;
}

// -------------------------------------------------------------


function trace($str){
	if(defined('$dolog')&&$dolog){
		echo $str;
	}
}

//jhon at stockton dot com dot com
//04-Jun-2007 01:02
// a function for resize the images(png,jpg,gif) in a directory
//for the png you must have the zlib actived
//$diror origin directory
//$dirdest destination directory
//$val value of resize(1,2,3..)
//$qual quality(80 if you don't know)
function create_thumbnail($file){
$qual=80;

// -------------------------------------------------------------

                 $k=explode(".",$file);
            if(strpos($k[1],"jpg")===0 || strpos($k[1],"jpeg")===0){
            $salva=$dirdest.$file;
                    $image=$diror.$file;
            $im =imagecreatefromjpeg("$image");
            $x=imagesx($im);
            $y=imagesy($im);   
            $thumbnail=imagecreatetruecolor($x/$val,$y/$val);
            $im_ridimensionata=imagecopyresized( $thumbnail, $im, 0, 0, 0, 0, $x/$val,
            $y/$val, $x, $y);
            imagejpeg($thumbnail, $salva, $q);        
                    }
            elseif(strpos($k[1],"gif")===0){
            $salva=$dirdest.$file;
                    $image=$diror.$file;
            $im =imagecreatefromgif("$image");
            $x=imagesx($im);
            $y=imagesy($im);   
            $thumbnail=imagecreatetruecolor($x/$val,$y/$val);
            $im_ridimensionata=imagecopyresized( $thumbnail, $im, 0, 0, 0, 0, $x/$val,
            $y/$val, $x, $y);
            imagegif($thumbnail, $salva, $q);
                }
            elseif(strpos($k[1],"png")===0){
            $salva=$dirdest.$file;
                    $image=$diror.$file;
            $im =imagecreatefrompng("$image");
            $x=imagesx($im);
            $y=imagesy($im);   
            $thumbnail=imagecreatetruecolor($x/$val,$y/$val);
            $im_ridimensionata=imagecopyresized( $thumbnail, $im, 0, 0, 0, 0, $x/$val,
            $y/$val, $x, $y);
            imagepng($thumbnail, $salva, $q);
                }
            else{
                echo "File not compatible(no jpg,gif or png)";
            }    
}


?>
